package com.mall507.fivepeaks.comn.adapter;

import android.os.Parcelable;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.ImageView;

import java.util.List;

public class ShopImageAdapter extends PagerAdapter {
	private List<ImageView> imageViews;
	
	public ShopImageAdapter(List<ImageView> imageViews){
		this.imageViews=imageViews;
	}

	@Override
	public int getCount() {
		return imageViews.size();
	}

	@Override
	public Object instantiateItem(View view, int index) {
		try {
			if (index >= imageViews.size()) {
				((ViewPager) view).removeView(imageViews.get(imageViews.size() - 1));
				((ViewPager) view).addView(imageViews.get(imageViews.size() - 1));
				return imageViews.get(imageViews.size() - 1);
			} else {
				((ViewPager) view).removeView(imageViews.get(index));
				((ViewPager) view).addView(imageViews.get(index));
				return imageViews.get(index);
			}
		} catch (Exception e) {
			e.printStackTrace();
			return imageViews.get(imageViews.size() - 1);
		}
	}

	@Override
	public void destroyItem(View arg0, int arg1, Object arg2) {
		// ((ViewPager) arg0).removeView((View) arg2);
	}

	@Override
	public boolean isViewFromObject(View arg0, Object arg1) {
		return arg0 == arg1;
	}

	@Override
	public void restoreState(Parcelable arg0, ClassLoader arg1) {

	}

	@Override
	public Parcelable saveState() {
		return null;
	}

	@Override
	public void startUpdate(View arg0) {

	}

	@Override
	public void finishUpdate(View arg0) {

	}

}
